/*定义一个全局函数*/
//异步函数
let myAsyncAjax =  function(url, data, type,successCallback,errorCallback) {
    let da;
    $.ajax({
        url: url,
        data: type == 'post'?JSON.stringify(data):data,
        type: type == null ? 'get' : 'post',
        dataType: 'json',
        contentType:"application/json",
        async:'false',
        success: successCallback,
        error:errorCallback
    });
    return da;
}

//同步函数
let mySyncAjax = function (url, data, type,successCallback,errorCallback) {
    $.ajax({
        url: url,
        data:  type == 'post'?JSON.stringify(data):data,
        type: type == null ? 'get' : 'post',
        contentType:"application/json",
        dataType: 'json',
        success:successCallback,
        error:errorCallback
    });
}
function setCookie(name,value)
{
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function clearCookie(name) {
    setCookie(name, "", -1);
}
function clearAllCookie() {
    var date=new Date();
    date.setTime(date.getTime()-10000);
    var keys=document.cookie.match(/[^ =;]+(?=\=)/g);
    console.log("需要删除的cookie名字："+keys);
    if (keys) {
        for (var i =  keys.length; i--;)
            document.cookie=keys[i]+"=0; expire="+date.toGMTString()+"; path=/";
    }
}
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}
